package com.wlr.blog.web.common.utils;

import java.util.Random;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/12/7 14:30
 */
public class MailUtils {
    public static String generateCode(int n) {
        StringBuilder result = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            int type = random.nextInt(3);
            switch (type) {
                case 0:
                    char c0 = (char) (random.nextInt(26) + 65);
                    result.append(c0);
                    break;
                case 1:
                    char c1 = (char) (random.nextInt(26) + 97);
                    result.append(c1);
                    break;
                case 2:
                    int m = random.nextInt(10);//生成0~9的随机数
                    result.append(m);
                    break;
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(MailUtils.generateCode(4));
    }
}
